﻿using System;

namespace Cpu6502.Opcodes
{
    public class CPY_I : Opcode
    {
        public CPY_I()
        {
            this.CpuCycles = 2;
            this.AddressType = CPU.AddressType.Immediate;
        }
        public override void Execute()
        {
            int data = base.Argument;

            data = (CPU.Registers.Y - data);
            CPU.Registers.P.C = (data < 0x100);
            CPU.Registers.P.N = (((data << 7) & 1) != 0);
            CPU.Registers.P.Z = ((data &= 0xff) == 0);
        }
    }

    public class CPY_A : Opcode
    {
        public CPY_A()
        {
            this.CpuCycles = 4;
            this.AddressType = CPU.AddressType.Absolute;
        }
        public override void Execute()
        {
            int data =
                CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.Absolute)
                ];

            data = CPU.Registers.Y - data;
            CPU.Registers.P.C = (data < 0x100);
            CPU.Registers.P.N = (((data << 7) & 1) != 0);
            CPU.Registers.P.Z = ((data &= 0xff) == 0);
        }
    }
    
    public class CPY_ZP : Opcode
    {
        public CPY_ZP()
        {
            this.CpuCycles = 3;
            this.AddressType = CPU.AddressType.ZeroPage;
        }
        public override void Execute()
        {
            int data =
                CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.ZeroPage)
                ];

            data = CPU.Registers.Y - data;
            CPU.Registers.P.C = (data < 0x100);
            CPU.Registers.P.N = (((data << 7) & 1) != 0);
            CPU.Registers.P.Z = ((data &= 0xff) == 0);
        }
    }    
}